DEFINITION MODULE DCPicCnv;

(*---------------------------------------------------------------------*)
(*   LOW LEVEL Picture Conversion Routines For DegasConvert            *)
(*                                                                     *)
(*   THESE ROUTINES ARE USED BY DegasCPC to PROCESS PICTURES.          *)
(*                                                                     *)
(*   The reason I choose to split the conversion routines is because   *)
(*   the higher level routines need to access the screen to show the   *)
(*   user what is happening. This way the low-level conversion         *)
(*   module doesn't need to know about the screen, this hides          *)
(*   implentation details.                                             *)
(*                                                                     *)
(*   Note: There are functions for each type of resolution, this is    *)
(*         for efficiency reasons. Also for efficiency reasons there   *)
(*         will be routines to convert ONE picture line. The picture   *)
(*         to be operated on will be passed each time along with the   *)
(*         print palette to go with it.                                *)
(*                                                                     *)
(*   The first version of this program was rather simple in the way it *)
(*   allocated black and white patterns to the colours in the picture  *)
(*   to be converted. Specifically, it just used the bits in the index *)
(*   number of a pixel as the pattern to plot.( i.e. a dark colour may *)
(*   come out light in the conversion ). A better way would be to look *)
(*   at the colours in the palette and allocate a shade to it depending*)
(*   on the intensity of the colour of the pixel. This is what is      *)
(*   implemented in this version of the program.                       *)
(*                                                                     *)
(*   For a low-res picture there are 16 colours of different intensity *)
(*   spread through the palette. I want to allocate print bit patterns *)
(*   ( a number from 0 to 15 ) to each entry in the palette so that    *)
(*   light colours print light and dark colours print dark. To         *)
(*   simplify(!) this process I intend to sort the palette by          *)
(*   intensity, allocate the print patterns to the palette in order    *)
(*   of increasing number of on-bits in the print bit pattern.         *)
(*                                                                     *)
(*   Degas Picture Functions:                                          *)
(*      1) Return the colour index of pixel                            *)
(*      2) Return the Red,Green,Blue components of a palette entry     *)
(*      3) Assign a print bit pattern,got from user,to a palette entry *)
(*      4) Assign Default print bit patterns to the picture palette    *)
(*      5) Return the print bit pattern for a pixel                    *)
(*      6) Set a pixel in the hi-res picture                           *)
(*      7) Clear all pixels in the hi-res picture                      *)
(*                                                                     *)
(*                                                                     *)
(*                                                                     *)
(*   Version 1.1      August 1987                    L.G.Miller        *)
(*---------------------------------------------------------------------*)

FROM DCGlobal           IMPORT  DegasPicture,
                                Palette,
                                PrintPalette,
                                PrintBitPatternSet,
				LowRes16PixelsPtr,
				LowResScreenLinePtr,
				LowResScreen,
				MedRes16PixelsPtr,
			        MedResScreenLinePtr,
				MedResScreen,
				HiRes16PixelsPtr,
			        HiResScreenLinePtr,
				HiResScreen;

(* return address of pixel group and the bit number.
   Note: The leftmost pixel is bit 0. This is due to the
         way this compiler numbers bits in a bitset. *)
PROCEDURE LowRes16PixelsAddr (     x, y : CARDINAL;
			       VAR picture : LowResScreen;
			       VAR PixelNo : CARDINAL;
			       VAR PGPtr   : LowRes16PixelsPtr);

PROCEDURE MedRes16PixelsAddr (     x, y : CARDINAL;
			       VAR picture : MedResScreen;
			       VAR PixelNo : CARDINAL;
			       VAR PGPtr   : MedRes16PixelsPtr);

PROCEDURE HiRes16PixelsAddr (     x, y : CARDINAL;
			      VAR picture : HiResScreen;
			      VAR PixelNo : CARDINAL;
			      VAR PGPtr   : HiRes16PixelsPtr);


(*----------------------------------------------------------------------*)
(* Find out the Colour index of a low-res pixel.                        *)
(*----------------------------------------------------------------------*)
PROCEDURE QueryXYLowResPixelIndex( x, y : CARDINAL;
			           Picture : DegasPicture ) : CARDINAL;


(*----------------------------------------------------------------------*)
(* Find out the Colour index of a low-res pixel.                        *)
(*----------------------------------------------------------------------*)
PROCEDURE QueryLowResPixelIndex( PixelNo : CARDINAL;
			         PGPtr : LowRes16PixelsPtr ) : CARDINAL;


(*----------------------------------------------------------------------*)
(* Find out the red,green,blue components of a low-res pixel            *)
(*----------------------------------------------------------------------*)
PROCEDURE QueryLowResPixelColour ( PixelNo : CARDINAL;
			           PGPtr   : LowRes16PixelsPtr;
                                   VAR palette : Palette;
                                   VAR red, green, blue : CARDINAL );


(*----------------------------------------------------------------------*)
(* Return the Print bit Pattern associated with the Low Res pixel.      *)
(*----------------------------------------------------------------------*)
PROCEDURE QueryLowResPixelPBPattern ( PixelNo : CARDINAL;
                                      PGPtr   : LowRes16PixelsPtr;
                                      VAR printpalette : PrintPalette;
                                      VAR pbp     : PrintBitPatternSet );


(*----------------------------------------------------------------------*)
(* Medium resolution versions of the above                              *)
(*----------------------------------------------------------------------*)


(*----------------------------------------------------------------------*)
(* Find out the Colour index of a med-res pixel.                        *)
(*----------------------------------------------------------------------*)
PROCEDURE QueryXYMedResPixelIndex( x, y : CARDINAL;
			           Picture : DegasPicture ) : CARDINAL;


(*----------------------------------------------------------------------*)
(* Find out the Colour index of a low-res pixel.                        *)
(*----------------------------------------------------------------------*)
PROCEDURE QueryMedResPixelIndex  ( PixelNo : CARDINAL;
				   PGPtr : MedRes16PixelsPtr ) : CARDINAL;


(*----------------------------------------------------------------------*)
(* Find out the red,green,blue components of a low-res pixel            *)
(*----------------------------------------------------------------------*)
PROCEDURE QueryMedResPixelColour (     PixelNo : CARDINAL;
				       PGPtr : MedRes16PixelsPtr;
                                   VAR palette : Palette;
                                   VAR red, green, blue : CARDINAL );


(*----------------------------------------------------------------------*)
(* Return the Print bit Pattern associated with the Med Res pixel.      *)
(*----------------------------------------------------------------------*)
PROCEDURE QueryMedResPixelPBPattern (     PixelNo : CARDINAL;
				          PGPtr : MedRes16PixelsPtr;
                                      VAR printpalette : PrintPalette;
                                      VAR pbp     : PrintBitPatternSet );



(*----------------------------------------------------------------------*)
(* Assign a print bit pattern to a palette entry                        *)
(*----------------------------------------------------------------------*)
PROCEDURE SetPBPattern ( VAR printpalette : PrintPalette;
                             colourindex  : CARDINAL;
                             pbp          : PrintBitPatternSet );


(*----------------------------------------------------------------------*)
(* Find out the current print bit pattern for a palette entry           *)
(*----------------------------------------------------------------------*)
PROCEDURE QueryPBPattern ( VAR printpalette : PrintPalette;
                               colourindex  : CARDINAL;
                           VAR pbp          : PrintBitPatternSet );



(*----------------------------------------------------------------------*)
(*----------------------------------------------------------------------*)
(* Routines to process the output hi-res picture                        *)
(*----------------------------------------------------------------------*)
(*----------------------------------------------------------------------*)

(*----------------------------------------------------------------------*)
(* Reset all the pixels in the output hi-res picture                    *)
(*----------------------------------------------------------------------*)
PROCEDURE ClearHiRes ( VAR screen : HiResScreen );


(*----------------------------------------------------------------------*)
(* Set on one hi-res pixel                                              *)
(*----------------------------------------------------------------------*)
PROCEDURE SetHiResPixel (     PixelNo : CARDINAL;
                              PGPtr   : HiRes16PixelsPtr );


(*----------------------------------------------------------------------*)
(* This routine will plot the pattern in a square.                      *)
(*----------------------------------------------------------------------*)
PROCEDURE SetLowToHiResPBPattern (     x, y   : CARDINAL;
                                   VAR screen : HiResScreen;
                                       bpb    : PrintBitPatternSet );


(*----------------------------------------------------------------------*)
(* This routine will plot the pattern in a rectangle                    *)
(*----------------------------------------------------------------------*)
PROCEDURE SetMedToHiResPBPattern (     x, y   : CARDINAL;
                                   VAR screen : HiResScreen;
                                       pbp    : PrintBitPatternSet );


(*----------------------------------------------------------------------*)
(* Convert ONE line of input low-res picture to output hi-res picture.  *)
(*----------------------------------------------------------------------*)
PROCEDURE ConvertLowToHiResOneLine ( VAR inpic, outpic : DegasPicture;
                                     VAR ppalette      : PrintPalette;
                                         inlineno      : CARDINAL );


(*----------------------------------------------------------------------*)
(* Convert ONE line of input med-res picture to output hi-res picture   *)
(*----------------------------------------------------------------------*)
PROCEDURE ConvertMedToHiResOneLine ( VAR inpic, outpic : DegasPicture;
                                     VAR ppalette      : PrintPalette;
                                         inlineno      : CARDINAL );


(*----------------------------------------------------------------------*)
(* Sort print palette.                                                  *)
(*----------------------------------------------------------------------*)
PROCEDURE SortByColour( VAR ppalette      : PrintPalette;
                            NumberOfItems : CARDINAL );


PROCEDURE SortByIndex( VAR ppalette      : PrintPalette;
                            NumberOfItems : CARDINAL );




END DCPicCnv.

